#!/usr/bin/python3
import sys
import re

def part1():
    print('part 1')
    s = 0
    for line in sys.stdin:
        digits = [int(d) for d in re.findall(r'\d', line.strip())]
        number = digits[0] * 10 + digits[-1]
        s += number
    print(s)

def replace(string):
    return string. \
            replace('oneight', '18'). \
            replace('twone', '21'). \
            replace('threeight', '38'). \
            replace('fiveight', '58'). \
            replace('sevenine', '79'). \
            replace('eightwo', '82'). \
            replace('eighthree', '83'). \
            replace('nineight', '98'). \
            replace('one', '1'). \
            replace('two', '2'). \
            replace('three', '3'). \
            replace('four', '4'). \
            replace('five', '5'). \
            replace('six', '6'). \
            replace('seven', '7'). \
            replace('eight', '8'). \
            replace('nine', '9')

def part2():
    print('part 2')
    s = 0
    for line in sys.stdin:
        line = replace(line.strip())
        digits = [int(d) for d in re.findall(r'\d', line)]
        number = digits[0] * 10 + digits[-1]
        s += number
    print(s)

if sys.argv[1] in '1':
    part1()
else:
    part2()
